//
//  SmartCounselMainView.m
//  Zinipad
//
//  Created by ZeLkOvA on 12. 5. 24..
//  Copyright (c) 2012년 __MyCompanyName__. All rights reserved.
//

#import "SmartCounselMainView.h"
#import "ZinMainViewController.h"
#import "SmartCounselRecordView.h"
#import "DatabaseManager.h"

@interface SmartCounselMainView ()

@end

@implementation SmartCounselMainView
@synthesize counselList;
@synthesize scrollView;
@synthesize PopupCustomerInfo;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self topMenuView];
    [self leftMenuView];
    [self ResultViewTopMenu];
    
    self.counselList = [NSMutableArray array];
    self.counselList = [DatabaseManager customerList];
    SelectIndex = 0;

    if([self.counselList count] == 0)
    {
//        UILabel* buttonSubLabel = [[UILabel alloc] init];
//        [buttonSubLabel setTextAlignment:UITextAlignmentCenter];
//        [buttonSubLabel setTextColor:[UIColor whiteColor]];
//        [buttonSubLabel setFont:[UIFont systemFontOfSize:12.0f]];
//        [buttonSubLabel setBackgroundColor:[UIColor clearColor]];
    }
    else 
    {
        [self ResultMainView];
        NSLog(@"%d",[self.counselList count]);
    }
   
}
-(void)topMenuView
{
    [self.view setBackgroundColor:[UIColor blackColor]];
    UIButton* zinButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [zinButton setFrame:CGRectMake(10,10 ,100, 36)];
    [zinButton setTitle:[NSString stringWithFormat:@"Z:IN"] forState:UIControlStateNormal];
    [zinButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [zinButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [zinButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [zinButton addTarget:self action:@selector(zinButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zinButton];
    
    UIButton* zinSampleBookButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [zinSampleBookButton setFrame:CGRectMake(250,10 ,130, 36)];
    [zinSampleBookButton setTitle:[NSString stringWithFormat:@"Z:IN 샘플북"] forState:UIControlStateNormal];
    [zinSampleBookButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [zinSampleBookButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [zinSampleBookButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [zinSampleBookButton addTarget:self action:@selector(zinSampleBookButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zinSampleBookButton];
    
    UIButton* smartCounselButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [smartCounselButton setFrame:CGRectMake(380,10 ,150, 36)];
    [smartCounselButton setTitle:[NSString stringWithFormat:@"Smart 삼담기록"] forState:UIControlStateNormal];
    [smartCounselButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [smartCounselButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [smartCounselButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [smartCounselButton addTarget:self action:@selector(smartCounselButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:smartCounselButton];
    
    UIButton* mBrochureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [mBrochureButton setFrame:CGRectMake(550,10 ,130, 36)];
    [mBrochureButton setTitle:[NSString stringWithFormat:@"M 브로셔"] forState:UIControlStateNormal];
    [mBrochureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [mBrochureButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [mBrochureButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [mBrochureButton addTarget:self action:@selector(mBrochureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:mBrochureButton];
    
    
    UIButton* MatchingButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [MatchingButton setFrame:CGRectMake(1024-70*4,10, 70, 36)];
    [MatchingButton setTitle:[NSString stringWithFormat:@"매칭하기"] forState:UIControlStateNormal];
    [MatchingButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [MatchingButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [MatchingButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [MatchingButton addTarget:self action:@selector(MatchingButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:MatchingButton];
    
    UIButton* CalButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [CalButton setFrame:CGRectMake(1024-70*3,10 , 70, 36)];
    [CalButton setTitle:[NSString stringWithFormat:@"소요량계산"] forState:UIControlStateNormal];
    [CalButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [CalButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [CalButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [CalButton addTarget:self action:@selector(CalButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:CalButton];
    
    UIButton* SetButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [SetButton setFrame:CGRectMake(1024-70*2,10 , 70, 36)];
    [SetButton setTitle:[NSString stringWithFormat:@"설정"] forState:UIControlStateNormal];
    [SetButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [SetButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [SetButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [SetButton addTarget:self action:@selector(SetButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:SetButton];
    
    UIButton* HelpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [HelpButton setFrame:CGRectMake(1024-70, 10, 70, 36)];
    [HelpButton setTitle:[NSString stringWithFormat:@"HELP"] forState:UIControlStateNormal];
    [HelpButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [HelpButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [HelpButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [HelpButton addTarget:self action:@selector(HelpButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:HelpButton];

}
-(void)zinButtonPressed:(id)sender
{
    ZinMainViewController* zinMainViewController = [[ZinMainViewController alloc] init];
    [self.navigationController pushViewController:zinMainViewController animated:YES];

}

-(void)zinSampleBookButtonPressed:(id)sender
{
    
}
-(void)smartCounselButtonPressed:(id)sender
{
    
}
-(void)mBrochureButtonPressed:(id)sender
{
    
}

-(void)leftMenuView
{
    UILabel* SmartCounselLb = [[UILabel alloc] initWithFrame:CGRectMake(40, 80, 140, 40)];
    [SmartCounselLb setTextColor:[UIColor colorWithRed:0.36f green:0.36f blue:0.36f alpha:1.0f]];
    [SmartCounselLb setBackgroundColor:[UIColor whiteColor]];
    [SmartCounselLb setLineBreakMode:UILineBreakModeWordWrap];
    [SmartCounselLb setText:@"Smart 상담기록"];
    [self.view addSubview:SmartCounselLb];
 
    UIButton* CounselRecordWatchButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [CounselRecordWatchButton setFrame:CGRectMake(30,150,160,40)];
    [CounselRecordWatchButton setTitle:[NSString stringWithFormat:@"상담기록보기"] forState:UIControlStateNormal];
    [CounselRecordWatchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [CounselRecordWatchButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [CounselRecordWatchButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [CounselRecordWatchButton addTarget:self action:@selector(CounselRecordWatchButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:CounselRecordWatchButton];
    
    UIButton* CounselRecordButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [CounselRecordButton setFrame:CGRectMake(30,210,160,40)];
    [CounselRecordButton setTitle:[NSString stringWithFormat:@"상담기록하기"] forState:UIControlStateNormal];
    [CounselRecordButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [CounselRecordButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [CounselRecordButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [CounselRecordButton addTarget:self action:@selector(CounselRecordButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:CounselRecordButton];
    
    UIButton* CounselRecordShareButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [CounselRecordShareButton setFrame:CGRectMake(30,270,160,40)];
    [CounselRecordShareButton setTitle:[NSString stringWithFormat:@"상담내용공유하기"] forState:UIControlStateNormal];
    [CounselRecordShareButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [CounselRecordShareButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [CounselRecordShareButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [CounselRecordShareButton addTarget:self action:@selector(CounselRecordShareButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:CounselRecordShareButton];

}

-(void)CounselRecordWatchButtonPressed:(id)sender
{
    
}
-(void)CounselRecordButtonPressed:(id)sender
{
    SmartCounselRecordView* smartCounselRecordView = [[SmartCounselRecordView alloc] init];
    [self.navigationController pushViewController:smartCounselRecordView animated:YES];
}
-(void)CounselRecordShareButtonPressed:(id)sender
{
    
}

-(void)ResultViewTopMenu
{
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(buttonLongPressed:)];
    longPress.minimumPressDuration = 0.5;
    

    UIButton* RegistrationFirstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [RegistrationFirstButton setFrame:CGRectMake(250,80,100,40)];
    [RegistrationFirstButton setTitle:[NSString stringWithFormat:@"등록순"] forState:UIControlStateNormal];
    [RegistrationFirstButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [RegistrationFirstButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [RegistrationFirstButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [RegistrationFirstButton addTarget:self action:@selector(RegistrationFirstButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:RegistrationFirstButton];
    
    UIButton* NameFirstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [NameFirstButton setFrame:CGRectMake(370,80,100,40)];
    [NameFirstButton setTitle:[NSString stringWithFormat:@"이름순"] forState:UIControlStateNormal];
    [NameFirstButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [NameFirstButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [NameFirstButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [NameFirstButton addTarget:self action:@selector(NameFirstButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
 
    
    [self.view addSubview:NameFirstButton];
}

-(void)RegistrationFirstButtonPressed:(id)sender
{
    
}
-(void)NameFirstButtonPressed:(id)sender
{
    
}

-(void)ResultMainView
{
    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(250, 130, 1024-270, 748-160)];
    [scrollView setBackgroundColor:[UIColor whiteColor]];
    int buttonWidth = 130;
    int buttonHeight = 130;
    int buttonMarignRight = 40;
    int buttonMarginBottom = 65;
    int rowCount = scrollView.frame.size.width / (buttonWidth + buttonMarignRight );
    int buttonX = 0;
    int buttonY = 0;
    [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, (buttonHeight + buttonMarginBottom) * (int)ceil([self.counselList count] / (float)rowCount))];
    
    //    NSLog(@"%d", (buttonHeight + buttonMarginBottom) * (int)ceil(_xmlNodeCountArray.count / (float)rowCount));
      
    for(int i = 0; i < [self.counselList count]; i++)
    {
//        NSString* pageThumbImg = [NSString stringWithFormat:@"img_project_b_file.png"];
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(buttonLongPressed:)];
        longPress.minimumPressDuration = 0.5;
        
        NSMutableDictionary* Datadic = [NSMutableDictionary dictionary];
        Datadic = [self.counselList objectAtIndex:i];
        NSString* pageTitle = [Datadic objectForKey:@"C_name"];
        UIButton *eventButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        buttonX = (i % rowCount) * (buttonWidth + buttonMarignRight) + 40;
        buttonY = (buttonHeight + buttonMarginBottom) * (i / rowCount) + 31;
        [eventButton setTag:i];
        
        [eventButton addGestureRecognizer:longPress];
        
        UILabel* DateLb = [[UILabel alloc] initWithFrame:CGRectMake(5, 80,buttonWidth-10, 20)];
        [DateLb setTextColor:[UIColor colorWithRed:0.36f green:0.36f blue:0.36f alpha:1.0f]];
        [DateLb setText:[Datadic objectForKey:@"C_date"]];
        [DateLb setBackgroundColor:[UIColor clearColor]];
        [DateLb setTextAlignment:UITextAlignmentCenter]; 
        [eventButton addSubview:DateLb];
        
        UILabel* TimeLb = [[UILabel alloc] initWithFrame:CGRectMake(5, 100,buttonWidth-10, 20)];
        [TimeLb setTextColor:[UIColor colorWithRed:0.36f green:0.36f blue:0.36f alpha:1.0f]];
        [TimeLb setText:[Datadic objectForKey:@"C_time"]];
        [TimeLb setBackgroundColor:[UIColor clearColor]];
        [TimeLb setTextAlignment:UITextAlignmentCenter]; 
        [eventButton addSubview:TimeLb];

        [eventButton setFrame:CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight)];
        [eventButton setTitle:pageTitle forState:UIControlStateNormal];
//        [eventButton setBackgroundImage:[UIImage imageNamed:pageThumbImg] forState:UIControlStateNormal];
        
        [eventButton addTarget:self action:@selector(/*버튼눌렀을때실행될핸들러함수*/projectButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [eventButton setContentEdgeInsets:UIEdgeInsetsMake(-30, 0, 0, 0)];  // 중앙이 원점으로 텍스트위치 (top, left, bottom, right)
        [eventButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [scrollView addSubview:eventButton];
        
    }
    
    [self.view addSubview:scrollView];
    
}
- (void)buttonLongPressed:(UILongPressGestureRecognizer *)sender
{    
//    NSLog(@"LongPress!!!!!");
    if(sender.state == UIGestureRecognizerStateBegan) 
    { 
      
        NSLog(@"LongPress!!!!!");
        NSLog(@"%d",sender.view.tag);
    }   
}


-(void)projectButtonPressed:(id)sender
{
    SelectIndex = [sender tag];
    NSMutableDictionary* Data = [NSMutableDictionary dictionary];
    if([self.counselList count] == 0)
    {
        NSLog(@"없음");
    }
    NSLog(@"%d",[self.counselList count] );
    Data = [self.counselList objectAtIndex:SelectIndex];
    
    PopupCustomerInfo = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 748)];
    [PopupCustomerInfo setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:PopupCustomerInfo];
    
//    UIImage* backgroundImg = [UIImage imageNamed:@"a.png"];
//    UIImageView* backgroundImgView = [[UIImageView alloc] initWithImage:backgroundImg];
//    [backgroundImgView setFrame:CGRectMake(400, 160, 500, 530)];
//    [PopupCustomerInfo addSubview:backgroundImgView];
    
    UIView* temp = [[UIView alloc]initWithFrame:CGRectMake(400, 160, 500, 530)];
    [temp setBackgroundColor:[UIColor grayColor]];
    [PopupCustomerInfo addSubview:temp];
    
    UILabel* TitleNameLb = [[UILabel alloc] initWithFrame:CGRectMake(150, 10, 80, 40)];
    [TitleNameLb setTextColor:[UIColor colorWithRed:0.36f green:0.36f blue:0.36f alpha:1.0f]];
     NSString* pageTitle = [Data objectForKey:@"C_name"];
    [TitleNameLb setText:pageTitle];
    [TitleNameLb setFont:[UIFont systemFontOfSize:20]];
    [TitleNameLb setBackgroundColor:[UIColor clearColor]];
    [TitleNameLb setTextAlignment:UITextAlignmentCenter]; 
    [temp addSubview:TitleNameLb];
    
    UILabel* NameLb = [[UILabel alloc] initWithFrame:CGRectMake(200, 50, 80, 40)];
    [NameLb setTextColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]];
    [NameLb setText:pageTitle];
    [NameLb setFont:[UIFont systemFontOfSize:20]];
    [NameLb setBackgroundColor:[UIColor clearColor]];
    [NameLb setTextAlignment:UITextAlignmentCenter]; 
    [temp addSubview:NameLb];
    
    UILabel* PhoneLb = [[UILabel alloc] initWithFrame:CGRectMake(200, 80, 200, 40)];
    [PhoneLb setTextColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]];
    [PhoneLb setText:[Data objectForKey:@"C_phone"]];
    [PhoneLb setFont:[UIFont systemFontOfSize:20]];
    [PhoneLb setBackgroundColor:[UIColor clearColor]];
    [PhoneLb setTextAlignment:UITextAlignmentCenter]; 
    [temp addSubview:PhoneLb];
    
    UILabel* MailLb = [[UILabel alloc] initWithFrame:CGRectMake(200, 110, 200, 40)];
    [MailLb setTextColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]];
    [MailLb setText:[Data objectForKey:@"C_mail"]];
    [MailLb setFont:[UIFont systemFontOfSize:20]];
    [MailLb setBackgroundColor:[UIColor clearColor]];
    [MailLb setTextAlignment:UITextAlignmentCenter]; 
    [temp addSubview:MailLb];
    
    UILabel* ExpenseLb = [[UILabel alloc] initWithFrame:CGRectMake(200, 140, 200, 40)];
    [ExpenseLb setTextColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]];
    [ExpenseLb setText:[Data objectForKey:@"C_expanse"]];
    [ExpenseLb setFont:[UIFont systemFontOfSize:20]];
    [ExpenseLb setBackgroundColor:[UIColor clearColor]];
    [ExpenseLb setTextAlignment:UITextAlignmentCenter]; 
    [temp addSubview:ExpenseLb];
    
    UILabel* MemoLb = [[UILabel alloc] initWithFrame:CGRectMake(200, 170, 200, 40)];
    [MemoLb setTextColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]];
    [MemoLb setText:[Data objectForKey:@"C_memo"]];
    [MemoLb setFont:[UIFont systemFontOfSize:20]];
    [MemoLb setBackgroundColor:[UIColor clearColor]];
    [MemoLb setTextAlignment:UITextAlignmentCenter]; 
    [temp addSubview:MemoLb];
    
    UILabel* CounselItemLb = [[UILabel alloc] initWithFrame:CGRectMake(200, 200, 200, 40)];
    [CounselItemLb setTextColor:[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]];
    [CounselItemLb setText:[Data objectForKey:@"C_item"]];
    [CounselItemLb setFont:[UIFont systemFontOfSize:20]];
    [CounselItemLb setBackgroundColor:[UIColor clearColor]];
    [CounselItemLb setTextAlignment:UITextAlignmentCenter]; 
    [temp addSubview:CounselItemLb];
    
    NSArray* itemWallpaperList = [[NSArray alloc] init];
    itemWallpaperList = [DatabaseManager spliteString:[Data objectForKey:@"C_wallPaperImgName"]];
    
    NSArray* itemFlooringList = [[NSArray alloc] init];
    itemFlooringList = [DatabaseManager spliteString:[Data objectForKey:@"C_FlooringImgName"]];
    
     NSMutableArray* itemList = [[NSMutableArray alloc] init];
    for(int i = 0;i<[itemWallpaperList count];i++)
    {
        [itemList addObject:[itemWallpaperList objectAtIndex:i]];
    }
    for(int i = 0;i<[itemFlooringList count];i++)
    {
        [itemList addObject:[itemFlooringList objectAtIndex:i]];
    }
    
    [self PopupImgitemView:itemList view:temp];
    
    UIButton* PopupModifyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [PopupModifyButton setFrame:CGRectMake(500-100, 10, 50, 40)];
    [PopupModifyButton setTitle:[NSString stringWithFormat:@"수정"] forState:UIControlStateNormal];
    [PopupModifyButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [PopupModifyButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [PopupModifyButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [PopupModifyButton addTarget:self action:@selector(PopupModifyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [temp addSubview:PopupModifyButton];
    
    UIButton* PopupBackButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [PopupBackButton setFrame:CGRectMake(500-50, 10, 40, 40)];
    [PopupBackButton setTitle:[NSString stringWithFormat:@"X"] forState:UIControlStateNormal];
    [PopupBackButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [PopupBackButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [PopupBackButton setTitleEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 5)];
    [PopupBackButton addTarget:self action:@selector(PopupBackButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [temp addSubview:PopupBackButton];
    
}

-(void)PopupImgitemView:(NSMutableArray*)_list view:(UIView*)_tempView
{
     UIScrollView* itemScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(20, 340, 450, 170)];
    [itemScroll setBackgroundColor:[UIColor whiteColor]];
    int buttonWidth = 100;
    int buttonHeight = 50;
    int buttonMarignRight = 40;
    int buttonMarginBottom = 45;
    int rowCount = itemScroll.frame.size.width / (buttonWidth + buttonMarignRight );
    int buttonX = 0;
    int buttonY = 0;
    [itemScroll setContentSize:CGSizeMake(itemScroll.frame.size.width, (buttonHeight + buttonMarginBottom) * (int)ceil([_list count] / (float)rowCount))];
    
    for(int i = 0; i < [_list count]; i++)
    {
        UIImage* imgList = [UIImage imageNamed:[_list objectAtIndex:i]];
        buttonX = (i % rowCount) * (buttonWidth + buttonMarignRight) + 40;
        buttonY = (buttonHeight + buttonMarginBottom) * (i / rowCount) + 10;
        UIImageView* imgListView = [[UIImageView alloc] initWithImage:imgList];
        [imgListView setFrame:CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight)];
        [itemScroll addSubview:imgListView];
    }
    [_tempView addSubview:itemScroll];
}

-(void)PopupModifyButtonPressed:(id)sender
{
    
}
-(void)PopupBackButtonPressed:(id)sender
{
    [PopupCustomerInfo removeFromSuperview];
    [PopupCustomerInfo release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(void)dealloc
{
    [super dealloc];
//    [DatabaseManager closeDatabse];
//    [counselList release];
}

@end
